package nuaa.controller;

import nuaa.service.CollectionService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * 收藏控制器
 */
@Controller
@RequestMapping("/collection")
public class CollectionController {

    /*service层类*/
    CollectionService collectionService=new CollectionService();

    public CollectionController() throws IOException {
    }

    @RequestMapping("/deleteCollection")
    public String deleteCollection(Integer collectionId, HttpServletRequest request) throws IOException {
        //打印id
        System.out.println(collectionId);
        //将collectionId作为参数传到service层方法中
        collectionService.deleteCollection(collectionId,request);
        //重定向到原来页面
        //尝试重定向的时候加上参数
        System.out.println("删除完毕");
        return "redirect:/personalInformation?pageNum=5";
    }

    /**
     * 提交收藏
     */
    @RequestMapping("/addCollection")
    public @ResponseBody void addCollection(@RequestParam("groupId") Integer groupId) throws IOException {
        //传入的参数是收藏的出游地
        System.out.println("groupId="+groupId);
        collectionService.addCollection(groupId);
    }
}
